<template>
  <div>
    <div class="nav-box">
      <div class="nav-title">{{title}}</div>
      <div class="logout-box" v-on:click="logout">
        <i class="el-icon-switch-button"></i>
        <div class="logout-text">退出登陆</div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'navBarComponent',
  props: {
    title: {
      type: String,
      required: true
    }
  },
  methods: {
    // 退出登陆
    logout () {
      // 清楚本地session的用户名缓存
      sessionStorage.removeItem('ms_username')
      // replace代替push，防止回退
      this.$router.replace({ path: '/' })
    }
  }
}
</script>
<style lang="less" scoped>
  .nav-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: white;
    margin-bottom: 30px;
    .nav-title {
      font-size: 20px;
      width: 100px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 0 3px;
      text-align: center;
    }
    .logout-box {
      display: flex;
      justify-content: center;
      align-items: center;
      margin-right: 2px;
      .logout-text {
        font-size: 20px;
        margin: 2px;
      }
    }
  }
</style>
